package com.jrx.anytxn.reporting.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jrx.anytxn.common.uitl.BeanMapping;
import com.jrx.anytxn.common.uitl.StringUtils;
import com.jrx.anytxn.i18n.response.TxnPage;
import com.jrx.anytxn.param.constant.Constant;
import com.jrx.anytxn.reporting.dto.MrLoanAccountInfoRes;
import com.jrx.anytxn.reporting.entity.MrLoanAccountInfo;
import com.jrx.anytxn.reporting.mapper.ext.ExtMrLoanAccountInfoMapper;
import com.jrx.anytxn.reporting.service.ILoanAccountService;
import com.jrx.anytxn.transaction.entity.AmLoanMainInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Sunset
 * @version 1.0
 * @date 2020/4/15
 */
@Service
public class LoanAccountServiceImpl  implements ILoanAccountService {

    @Resource
    private ExtMrLoanAccountInfoMapper extMrLoanAccountInfoMapper;

    @Override
    public TxnPage<MrLoanAccountInfoRes> getLoansByCusIdAndLoanId(String channel,String customerId, String loanId, String tenantId,String beginDate, String endDate,Integer pageNum, Integer pageSize) {

        Page<AmLoanMainInfo> page = PageHelper.startPage(pageNum,pageSize);
        if(StringUtils.isBlank(beginDate)){
            beginDate=null;
        }
        if(StringUtils.isBlank(endDate)){
            endDate=null;
        }
        List<MrLoanAccountInfo> mrLoanAccountInfos = extMrLoanAccountInfoMapper.selectLoansByCusIdAndLoanId(channel,customerId, loanId, tenantId, beginDate, endDate);
        List<MrLoanAccountInfoRes> mrLoanAccountInfoRes = BeanMapping.copyList(mrLoanAccountInfos, MrLoanAccountInfoRes.class);
        return new TxnPage(pageNum,pageSize, page.getTotal(),mrLoanAccountInfoRes);
    }

    @Override
    public MrLoanAccountInfoRes getLoanByCusIdAndLoanId(String channel, String customerId, String loanId, String tenantId) {
        MrLoanAccountInfo mrLoanAccountInfo = extMrLoanAccountInfoMapper.selectLoanByCusIdAndLoanId(channel, customerId, loanId, tenantId);
        return BeanMapping.copy(mrLoanAccountInfo,MrLoanAccountInfoRes.class);
    }
}